package com.sensei.search.client;

import static org.jboss.netty.channel.Channels.pipeline;

import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
import org.jboss.netty.handler.codec.frame.LengthFieldPrepender;
import org.jboss.netty.handler.codec.protobuf.ProtobufDecoder;
import org.jboss.netty.handler.codec.protobuf.ProtobufEncoder;

import com.browseengine.bobo.protobuf.BrowseResultBPO;

public class SenseiClientPipelineFactory implements ChannelPipelineFactory {

	public ChannelPipeline getPipeline() throws Exception {
		ChannelPipeline p = pipeline();
		 p.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1048576, 0, 4, 0, 4));
		 p.addLast("protobufDecoder", new ProtobufDecoder(BrowseResultBPO.Result.getDefaultInstance()));
		 p.addLast("frameEncoder", new LengthFieldPrepender(4));
		 p.addLast("protobufEncoder", new ProtobufEncoder());
		 p.addLast("handler", new SenseiClientHandler());
		 return p;
	}

}
